package com.example.demo;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Bean
    public CommandLineRunner commandLineRunner() {
        return args -> {
            //初始化Zk
            DynamicDataSourceUtils.setZk(DynamicDataSourceUtils.config);
            //初始化druid数据源
            DynamicDataSourceUtils.initDataSource(DynamicDataSourceUtils.config);
            //设置zk listener
            DynamicDataSourceUtils.dynamicSetDatasource();

            for (int i = 0; i < 5; i++) {
                DynamicDataSourceUtils.randomConfig();
                Thread.sleep(2000);
            }

        };
    }
}